package leetcode;

public class Lc153 {

    public int findMin(int[] nums) {
        int l = 0, r= nums.length - 1;

        if (nums.length == 1)
            return nums[0];
        if (nums.length == 2)
            return Math.min(nums[0], nums[1]);
        int min = Integer.MAX_VALUE;
        while (l <= r) {
            int mid = (l + r) / 2;
            if (nums[l] <= nums[mid]) { //左边有序,最小值即为nums[l],之所以是<=,是考虑l == mid，即左边只有一个元素，也视为有序
                min = Math.min(min, nums[l]);
                l = mid + 1; //获取到左边的最小值后，再往右找
            } else { //右边有序
                min = Math.min(min, nums[mid]); //右边有序
                r = mid - 1;//再往左找
            }
        }
        return min;
    }


}
